using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Library.Utilities;

namespace NCS.Module.CMS.Web
{
    public partial class PdfView : CMSWebControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Buffer = true; //make sur
            Response.AddHeader("Content-Disposition", "inline;filename=mk.pdf");
            Response.ContentType = "application/pdf";
            string html = GetHtml();
            string error = MiscUtility.CreatePdfStream(Response.OutputStream, html);
            if (error.Length == 0)
            {
                Response.End();
            }
            else
            {
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Buffer = true; //make sur
                Response.ContentType = "text/html";
                Response.Write(html);
                Response.Write("<br/><h4 style=\"color: red;\">" + error + "</h4>");
            }
        }

        private string GetHtml()
        {
            string retVal = string.Empty;
            retVal += "<html>";
            retVal += "<head>";
            //retVal += "<style type=\"text/css\">.bg_zone5 {background:url(/images/HomePage/bg_zone5.jpg);height:26px; color:#ffffff;font-family:tahoma;font-size:11px;font-weight:bold;padding-left:37px;background-repeat: no-repeat;vertical-align:middle;}</style>";
            retVal += "</head>";
            retVal += "<body>";
            if (this.curDistInfo != null)
            {
                CMS.Library.Contents.ContentInfo info = NCS.Module.CMS.Library.Contents.ContentController.GetContent(this.curDistInfo.Distribution_ContentID);
                if (info != null)
                {
                    string zoneurl = this.BuildUrlByZone(this.curZone.Zone_ID, this.curZone.Portal_TabControlID);
                    retVal += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"538\">";
                    retVal += "<tr><td class=\"bg_zone5\"><a style=\"color:White; text-transform:uppercase;\" href=\""+ zoneurl +"\">";
                    retVal += this.curZone.Zone_Name;
                    retVal += "</a></td></tr><tr><td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"right\" height=\"20\" valign=\"top\">";
                    //retVal += "<a href=\"" + this.BuildUrlByPdf() + "\" target=\"_blank\"><img src=\"/Images/pdf_icon.gif\" height=\"13\" alt=\"pdf\" border=\"0\" /></a>";
                    //retVal += "<a href=\"" + this.BuildUrlBySendMail() + "\" target=\"_blank\"><img src=\"/Images/email.gif\" height=\"13\" alt=\"pdf\" border=\"0\" /></a>";
                    //retVal += "<a href=\"" + this.BuildUrlByPrintPreview() + "\" target=\"_blank\"><img src=\"/Images/print.gif\" height=\"13\" alt=\"pdf\" border=\"0\" /></a>";
                    retVal += "</td></tr><tr><td>";
                    retVal += info.Content_SubTitle + "<br/>";
                    retVal += info.Content_Headline;
                    retVal += "</td></tr><tr><td height=\"7\"></td></tr><tr><td><span>";
                    retVal += info.Content_CreateDate.ToString("dd/MM/yyy");
                    retVal += "</span></td></tr><tr><td height=\"5\"></td></tr><tr><td><div>";
                    retVal += " <img src=\"http://" + Request.Url.Host + info.Content_Avatar + "\" style=\"border: 1px solid rgb(7, 81, 154); width: 173px;\">";
                    retVal += "<div style=\"width: 173px; text-align: center\">";
                    retVal += info.Content_AvatarDescription + "</div></div>";
                    retVal += info.Content_Body + "</td></tr></table></td></tr></table>";
                }
            }
            retVal += "</body>";
            retVal += "<html>";
            return retVal;
        }
    }
}